const router = require('koa-router')()
const {add,list,applyCheckPass,ban,comList,getCarsById} =require( '../dao/carsDao')

router.prefix('/cars')


router.post('/add', async function (ctx, next) {
  const result = {}
  console.log(ctx.request.body)
  const res = await add(ctx.request.body);
  ctx.body = res
})
router.post('/ban', async function (ctx, next) {
  const result = {}
  console.log(ctx.request.body)
  const{id} =ctx.request.body
  const res = await ban(id);
  ctx.body = res
})

router.get('/list', async function (ctx, next) {
  const result = {}
  const res = await list(ctx.request.body);
  ctx.body = res;
})
router.post('/applyCheckPass', async function (ctx, next) {
  const result = {}
  const {id,pass} = ctx.request.body
  const res = await applyCheckPass({id,pass});
  ctx.body = res;
})
router.post('/rent', async function (ctx, next) {
  const result = {}
  const id = ctx.request.body
  const res = await applyCheckPass(id);
  ctx.body = res;
})
router.get('/commitList', async function (ctx, next) {
  const result = {}
  const res = await comList();
  console.log(res)
  ctx.body = res;
})
router.get('/getCarsById', async function (ctx, next) {
  const result = {}
  const id = (ctx.query.id)
  const res = await getCarsById(id);
  console.log(res)
  ctx.body = res;
})
module.exports = router
